package com.dbq.fast.business.login.api;

import com.dbq.fast.business.login.bean.WeChatProfile;
import com.dbq.fast.business.login.bean.WeChatToken;
import com.dbq.fast.common.net.RemoteApiCallBack;

import org.junit.Test;

import java.util.concurrent.CountDownLatch;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;

/**
 * Created by sunkai on 2017/10/26.
 */
public class LoginApiTest {

    @Test
    public void getWCProfile() throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        String token = "q6ohU8wZ28AxS115Z5ExePpjnj8aEULiLL6J-jUFs-85y0TGPaUPpgRJUd6BL8l_JBWgvhfGAftVaiuB21WeVFpM8tmlp8msuGNvQpYud_Y";
        String opeId = "oPekH1A1BK7NzsF7QqZi9k93vm3M";
        final WeChatProfile[] profile = new WeChatProfile[1];
        LoginApi.getWCProfile(token, opeId, new RemoteApiCallBack<WeChatProfile>() {
            @Override
            public void onSuccess(WeChatProfile weChatProfile) {
                profile[0] = weChatProfile;
                countDownLatch.countDown();
            }

            @Override
            public void onFail(int status, String message) {
                countDownLatch.countDown();
            }
        });
        countDownLatch.await();
        assertEquals("看我眼神",profile[0].getNickname());


    }

    @Test
    public void getUserInfo() throws Exception {
        //TODO
    }

    @Test
    public void getWCToken() throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        final WeChatToken[] token = new WeChatToken[1];
        String code = "001uSR3P0rJRS82B294P0GQH3P0uSR3B";
        LoginApi.getWCToken(code, new RemoteApiCallBack<WeChatToken>() {
            @Override
            public void onSuccess(WeChatToken weChatToken) {
                token[0] = weChatToken;
                countDownLatch.countDown();
            }

            @Override
            public void onFail(int status, String message) {
                countDownLatch.countDown();
            }
        });
        countDownLatch.await();
        assertNotNull(token[0]);

    }

}